﻿var  SELECT_TYPE = {
		SEARCH_SEC: 1,
		SEARCH_MIN: 2,
		SEARCH_HOUR: 3,
		
		}

function checkEndTime(startTime,endTime){
	var start=new Date(startTime.replace("-", "/").replace("-", "/"));
	var end=new Date(endTime.replace("-", "/").replace("-", "/"));
	if(end<start){
	 	return false;
	}
	return true;
}

function getPcInfoC2Sjson(){
    	var st = $("#idStartTime").val();
	    var ed = $("#idEndTime").val();

        var selectType = $("#idSelType").find("option:selected").text();
		var serverName = $("#idServer").find("option:selected").text();
		console.log("selectType=%s",selectType);
        console.log("serverName=%s",serverName);
		var selInt = 0;
        switch(selectType){
			case "按小时":
			{
				selInt = SELECT_TYPE.SEARCH_HOUR;
			}
			break;
			case "按分钟":
			{
				selInt = SELECT_TYPE.SEARCH_MIN;
			}
			break;
			case "按秒钟":
			{
				selInt = SELECT_TYPE.SEARCH_SEC;
			}
			break;
			default:
			{
				alert(selInt);
                return false;
            }
			break;
		}

        //my97卡死了时间，不会出现时间错误，不检测时间
        /*if(!checkEndTime(st,ed)){
                alert("结束时间小于开始时间！")
                return false;
        }*/

       var pcJson ={
                "startTime":st,
                "endTime":ed,
				"selType":selInt,
				"serverName":serverName,
        };
       return pcJson;
}

$("#btnSearch").click(function(){ 
	var c2sjsonData = getPcInfoC2Sjson();
	$.getJSON("/getPcInfo",c2sjsonData,function(data){
        InitEchart(data);
	}); 
});

var Report = function() {
	
	 var handleGetServerName = function() {
		 $.getJSON("/getServerName",function(data){  
			$.each(data, function(i, item){
				 $('#idServer').append("<option value=''>" + item + "</option>");
			});
		}); 
	 }
	
	return {
        //main function to initiate the module
        init: function() {
            handleGetServerName();
          
        }

    };
	
}();

function InitEchart(data){
    //临时读取json文件，以后修改为去url取
	var chartdom = document.getElementById("idchartcpuMem");
    var myChart = echarts.init(chartdom);
    var option_pcInfo =data;

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option_pcInfo);
}

